#pragma once

#include <cstdlib>
#include <sys/epoll.h>
#include "log.hpp"

class Epoll
{
public:
    static const int gsize;

public:
    static int CreateEpoll()
    {
        int epfd = epoll_create(gsize);
        if (epfd > 0)
            return epfd;
        logMessage(ERROR, "%s", "epfd申请失败");
        exit(5);
    }

    static bool CtlEpoll(int epfd, int oper, int sock, uint16_t events)
    {
        struct epoll_event ev;
        ev.events = events;
        ev.data.fd = sock;
        int n = epoll_ctl(epfd, oper, sock, &ev);
        return n == 0;
    }

    static int WaitEpoll(int epfd, struct epoll_event revs[], int maxevents, int timeout)
    {
        return epoll_wait(epfd, revs, maxevents, timeout);
    }
};
const int Epoll::gsize = 256;